var Game = cc.Class({
  extends: cc.Component,

  properties: () => ({
    player: {
      default: null,
      type: require("Player")
    },
    prefabManager: {
      default: null,
      type: require("PrefabManager")
    },
    configurationTable: {
      default: null,
      type: require("ConfigurationTable")
    },
    playerDisplay: {
      default: null,
      type: cc.Node
    },
    whiteBtn: {
      default: null,
      type: cc.Node
    },
    blackBtn: {
      default: null,
      type: cc.Node
    },
    // play按钮节点显示
    startGameDisplay: {
      default: null,
      type: cc.Node
    },
    // 暂停按钮节点
    pauseBtn: {
      default: null,
      type: cc.Node
    },
    // 分数节点显示
    scoreDisplay: {
      default: null,
      type: cc.Label
    },
    // 连击节点显示
    comboDisplay: {
      default: null,
      type: cc.Label
    },
    //连击动画
    comboAnm: {
      default: null,
      type: cc.Animation
    },
    // 加分动画
    scoreAnm: {
      default: null,
      type: cc.Animation
    },
    scoreAdd: {
      default: null,
      type: cc.Label
    },
    // 血量节点显示
    bloodDisplay: {
      default: null,
      type: cc.Label
    },
    // 血条节点显示
    hpBar: {
      default: null,
      type: cc.Node
    },
    // 游戏未开始背景音乐
    gameRedyAudio: {
      default: null,
      type: cc.AudioClip
    },
    // 游戏开始背景音乐
    gameStartAudio: { //gameBgAudio
      default: null,
      type: cc.AudioClip
    },
    // 游戏结束时播放音乐
    gameOverAudio: {
      default: null,
      type: cc.AudioClip
    },
    backGround: {
      default: null,
      type: cc.Node
    },
    backGroundRelSpeed: 0,
    backGroundOffX: 0,
    ground: {
      default: null,
      type: cc.Node
    },
    groundRelSpeed: 0,
    groundOffX: 0,

    groundUp: {
      default: null,
      type: cc.Node
    },
    groundUpSpeed: 0,
    groundUpOffX: 0,

    // 总段落met
    metArrPer: {
      default: [],
      type: ["String"]
    },
    // 总段落mst
    mstArrPer: {
      default: [],
      type: ["String"]
    },
    // 暂停界面节点
    panelPause: {
      default: null,
      type: cc.Node
    },
    // 准备遮罩，用于载入数据等待
    panelReady: {
      default: null,
      type: cc.Node
    },
    // 关卡等级
    levelNum: 0,
    // 关卡速度
    speed: 0,
    // 必杀技能展示
    skillBar: {
      default: null,
      type: cc.Animation
    },
    // 技能条动画
    BarSkill: {
      default: null,
      type: cc.Node
    },
    // 技能按钮
    skillBtn: {
      default: null,
      type: cc.Button
    },
    // 霸体按钮父节点
    batiBar: {
      default: null,
      type: cc.Node
    },
    uiAnim: {
      default: null,
      type: cc.Animation
    },
    // 技能按钮CD
    skillCD: {
      default: null,
      type: cc.Node
    },
    // 霸体按钮cd
    batiCD: {
      default: null,
      type: cc.Node
    },
    // 结算页面按钮节点
    endPageDisplay: {
      default: null,
      type: cc.Node
    },
    // 是否复活界面
    ifFuHuoDisplay: {
      default: null,
      type: cc.Node
    },
  }),

  // 初始化游戏
  onLoad: function () {
    this.panelReady.active = true;
    // 云
    wx.cloud.init({
      traceUser: true
    });
    // 云函数 获取 openid或者appid
    wx.cloud.callFunction({
      name: 'ganjiangmoye',
      complete: res => {
        var OPENID = res.result.userInfo.openId;
        this.getData(OPENID);
        console.log('云端获取用户数据: ', res.result.userInfo, OPENID);
      }
    });
    // 导入配置表
    this.configurationTable.init();

    // 赋值和取值
    cc.find("LevelData").getComponent("LevelData").updateLevelNum(this.levelNum, this.speed);
    var leveldata = cc.find("LevelData").getComponent("LevelData")
    this.levelNum = leveldata.levelNum;
    this.speed = leveldata.speed;
    console.log(this.levelNum, this.speed, "取值");

    // 获取地图坐标位置
    this.oBGX = this.backGround.x;
    this.oGroundX = this.ground.x;
    this.oGroundup = this.groundUp.x;
    // 判断是否开始了游戏的条件
    this.isRuning = false;
    // 按钮初始化 黑白键与暂停键不可点击 初始化必杀技特效关闭
    this.whiteBtn.getComponent(cc.Button).enabled = false;
    this.blackBtn.getComponent(cc.Button).enabled = false;
    this.pauseBtn.getComponent(cc.Button).enabled = false;
    this.skillBtn.getComponent(cc.Button).enabled = false;
    this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = false;
    this.skillCD.active = false;
    this.skillBar.stop();
    this.batiCD.active = false;
    // 初始化分数为0
    this.score = 0;
    // 初始连击数为0
    this.comboNum = 0;
    // 初始化计时器
    this._creatTimes = 0;
    // 初始化复活记录
    this.fuhuoNum = 1;
    this._skillTime = 0;
    this._totalNum = 0;
    this._skillShow = false;
    this.endPageDisplay.active = false;
    this.ifFuHuoDisplay.active = false;
    // 播放待机音乐
    cc.audioEngine.play(this.gameRedyAudio, true);
  },
  // 游戏开始
  startGame: function () {
    if(!this.tili) return;
    this.batiBtnOp();
    
    if (this.speed == 1) {
      this.prefabManager.mstMoveSpeed = 6;
    } else if (this.speed == 2) {
      this.prefabManager.mstMoveSpeed = 12;
    } else if (this.speed == 3) {
      this.prefabManager.mstMoveSpeed = 18;
    }
    // 平a技能cd
    this.pingA = 0;

    this.configurationTable.removeConfig();
    // 初始化血量
    this._bloodVolume = this.tili;
    this._creatTimes = 0;
    this._guaiwuNum = 0;
    this.resetScore();
    this.resetCombo();
    this.resetBlood();
    this.resetJumpEve();
    this.isRuning = true;
    this._isSkill = false;
    this._isBati = false;
    this.startGameDisplay.x = 3000;
    this.whiteBtn.getComponent(cc.Button).enabled = true;
    this.blackBtn.getComponent(cc.Button).enabled = true;
    this.pauseBtn.getComponent(cc.Button).enabled = true;
    this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = true;
    this.player.onPlayerStartMove();
    cc.audioEngine.stopAll();
    cc.audioEngine.play(this.gameStartAudio, true);
    // 打开碰撞检测
    cc.director.getCollisionManager().enabled = true;
    // 配置表导入
    this.configurationTable.addConfig(this.levelNum);
    // 键盘侦听事件开启
    cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.keyDonwn, this);
    this.skillCD.active = false;
    this.batiCD.active = false;
    this.uiDisplayOn();
  },
  // 更新
  update: function (dt) {
    if (!this.isRuning) return;
    if (this._bloodVolume <= 0 && this.fuhuoNum == 1) {
      this.ifFuHuoShow();
      return;
    } else if (this._bloodVolume <= 0 && this.fuhuoNum == 0) {
      this.gameOver();
      return
    }
    this.moveBg(dt);
    this.prefabManager.moveMst(dt);
    this._creatTimes += dt;
    this._skillTime += dt;
    if (this._skillTime >= 1) {
      this._totalNum += 1;
      this.BarSkill.getChildByName('Bar').getComponent(cc.ProgressBar).progress = this._totalNum / 100;
      if (this._totalNum >= 100) {
        this._totalNum = 100;
        this.BarSkill.getChildByName('Bar').getComponent(cc.ProgressBar).progress = this._totalNum / 100;
      }
      this._skillTime = 0;
    }
    if ((this._creatTimes > this.metArrPer[this._guaiwuNum]) && (this.metArrPer[this._guaiwuNum] != -1)) {
      // cc.log("创建",this._creatTimes,this.metArrPer[this._guaiwuNum],this._guaiwuNum);
      this.prefabManager.creatrMst(this.mstArrPer[this._guaiwuNum]);
      this._creatTimes = 0;
      this._guaiwuNum += 1;
      return;
    } else if ((this._creatTimes > this.metArrPer[this._guaiwuNum]) && (this.metArrPer[this._guaiwuNum] == -1)) {
      // cc.log("不创建",this._creatTimes,this.metArrPer[this._guaiwuNum],this._guaiwuNum,this.metArrPer.length - 1);
      this._creatTimes = 0;
      this._guaiwuNum += 1;
      return;
    }
    if ((this._guaiwuNum - 1) == (this.metArrPer.length - 1)) {
      this.metArrPer = [];
      this.mstArrPer = [];
      // 配置表导入
      this.configurationTable.addConfig(this.levelNum);
      this._guaiwuNum = 0;
      return;
    }
    // 必杀技触发计算
    if (this._totalNum >= this.zhengqi) {
      this.skillShowPlay();
    } else if (this._totalNum < this.zhengqi) {
      this.skillShowStop();
    }
    // 平a计算cd
    if(!this._isLeft || !this._isRight){
      this.pingA += dt;
      if(this.pingA >= 0.5) {
        this._isLeft = true;
        this._isRight = true;
        this.pingA = 0;
      }
    }
  },
  // 云端获取用户数据
  getData: function (OPENID) {
    var _this = this;
    console.log("getdata", OPENID);
    const db = wx.cloud.database();
    db.collection('ganjiangmoye').where({
        _openid: OPENID,
      })
      .get({
        success: function (res) {
          // 云端最高分和总金币获得 并赋值到本地
          _this._id = res.data[0]._id;
          _this.tili = res.data[0].tili;
          _this.zhengqi = res.data[0].zhengqi;
          _this.batiNum = res.data[0].batiNum;
          _this.totalMoney = res.data[0].totalMoney;
          _this.maxScore = res.data[0].maxScore;
          _this.batiBar.getChildByName('moji').getComponent(cc.Label).string = _this.batiNum.toString();
          if (_this.batiNum > 0) {
            this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = true;
          }
          console.log("ssss", _this.batiBar.getChildByName('moji').getComponent(cc.Label).string, _this.batiNum.toString(), _this.batiNum);
        },
        fail: function (res) {
          console.log("getData_fail_get", res);
        },
        complete: function (res) {
          _this.panelReady.active = false;
          console.log("getData_complete_get222", res);
        }
      })
  },
  //显示UI
  uiDisplayOn: function () {
    var animState = this.uiAnim.play('uiON');
    animState.wrapMode = cc.WrapMode.Reverse;
  },
  //隐藏UI
  uiDisplayOff: function () {
    var animState = this.uiAnim.play('uiON');
    animState.wrapMode = cc.WrapMode.Normal;
  },
  // 键盘事件
  keyDonwn: function (event) {
    var self = this;
    if (!self.isRuning) return;
    if (!self._isLeft) return;
    if (!self._isRight) return;

    switch (event.keyCode) {
      case cc.macro.KEY.a:
        cc.log("a键点击");
        self.whiteBtnEve();
        break;
      case cc.macro.KEY.d:
        cc.log("d键点击");
        self.blackBtnEve();
        break;
    }
  },

  // 开始移动
  moveBg: function (distance) {
    this.backGround.x -= this.backGroundRelSpeed;
    // 如果 x的位置 小于 (初始位置-舞台的宽) 则x位置等于初始位置
    if (this.backGround.x < (this.oBGX - this.backGroundOffX)) {
      this.backGround.x = this.oBGX;
    }
    this.ground.x -= this.groundRelSpeed;
    if (this.ground.x < (this.oGroundX - this.groundOffX)) {
      this.ground.x = this.oGroundX;
    }
    this.groundUp.x -= this.groundUpSpeed;
    if (this.groundUp.x < (this.oGroundup - this.groundUpOffX)) {
      this.groundUp.x = this.oGroundup;
    }
  },
  
  // 打击成功 加分 & 加连击
  gainScore: function (mst) {
    var beishu = 1;
    if(this.comboNum > 0 && this.comboNum <= 20) {
      beishu = 1;
    }else if(this.comboNum > 20 && this.comboNum <= 50) {
      beishu = 1.2;
    }else if(this.comboNum > 50 && this.comboNum <= 100) {
      beishu = 1.5;
    }else if(this.comboNum > 100 && this.comboNum <= 200) {
      beishu = 2;
    }else if(this.comboNum > 200) {
      beishu = 3;
    }
    if(mst.name == 'mst006' || mst.name == 'mst005') {
      this.score += Math.ceil(30 * this.speed * this.levelNum * beishu);
      this.scoreAdd.string = '+ ' + Math.ceil(30 * this.speed * this.levelNum * beishu).toString();
    }else if(mst.name == 'mst004' || mst.name == 'mst003') {
      this.score += Math.ceil(20 * this.speed * this.levelNum * beishu);
      this.scoreAdd.string = '+ ' + Math.ceil(20 * this.speed * this.levelNum * beishu).toString();
    }else if(mst.name == 'mst002' || mst.name == 'mst001') {
      this.score += Math.ceil(10 * this.speed * this.levelNum * beishu);
      this.scoreAdd.string = '+ ' + Math.ceil(10 * this.speed * this.levelNum * beishu).toString();
    }
    this.scoreAnm.play();

    // this.comboNum += 1;
    // 更新 scoreDisplay Label 的文字
    this.scoreDisplay.string = '得分: ' + this.score;
    // this.comboDisplay.string = this.comboNum.toString();
    // if (this.comboNum > 1) {
    //   this.comboAnm.play();
    // }
  },
  // 打击失败或主角被击中 扣血 & 连击中断
  deductBlood: function (mst) {
    var dmg;
    if(mst.name == 'mst006' || mst.name == 'mst005') {
      dmg = 3;
    }else if(mst.name == 'mst004' || mst.name == 'mst003') {
      dmg = 2;
    }else if(mst.name == 'mst002' || mst.name == 'mst001') {
      dmg = 1;
    }

    this._bloodVolume -= dmg;
    this.comboNum = 0;
    // 更新 bloodDisplay Label 的文字
    this.bloodDisplay.string = '体力: ' + this.tili.toString() + ' / ' + this._bloodVolume.toString();
    this.hpBar.width = ((500 / this.tili) * this._bloodVolume);
  },
  // 白键按下事件
  whiteBtnEve: function () {
    if (!this.isRuning) return;
    if (!this._isLeft) return;
    // this._isLeft = true;
    this._isLeft = false;
    this._isRight = false;
    this.player.jumpWhite();
  },
  // 黑键按下事件
  blackBtnEve: function () {
    if (!this.isRuning) return;
    if (!this._isRight) return;
    // this._isRight = true;
    this._isLeft = false;
    this._isRight = false;
    this.player.jumpBlack();
  },
  // 必杀技按下事件
  skillBtnEve: function () {
    if (!this.isRuning) return;
    if (this._isSkill) return;
    // this.bishajiOn = true;
    // this._isSkill = false;
    this.player.jumpSkill();
  },
  // 技能按钮自身的特效
  skillShowPlay: function () {
    if (this._skillShow) return;
    if (!this._skillShow) {
      this.skillBar.play();
      this.skillBtn.getComponent(cc.Button).enabled = true;
      this._skillShow = true;
    }
  },
  // 技能按钮自身的特效取消
  skillShowStop: function () {
    this.skillBar.setCurrentTime(0);
    this.skillBar.stop();
    this.skillBtn.getComponent(cc.Button).enabled = false;
  },
  // 霸体按钮事件
  batiBtnEve: function () {
    if (!this.isRuning) return;
    if (this._isBati) return;
    if (this.batiNum <= 0) return;
    this.batiNum -= 1;
    this.batiBtnOp();
    const db = wx.cloud.database();
    db.collection('ganjiangmoye').doc(this._id).update({
      data: {
        batiNum: this.batiNum
      }
    })
    this.batiBar.getChildByName('moji').getComponent(cc.Label).string = this.batiNum.toString();
    this.player.jumpBati();
  },
  // 霸体按钮显示状态
  batiBtnOp: function () {
    if (this.batiNum == 0) {
      this.batiBar.opacity = 150;
    } else {
      this.batiBar.opacity = 255;
    };
  },
  // 分数重置
  resetScore: function () {
    this.score = 0;
    // 更新 scoreDisplay Label 的文字
    this.scoreDisplay.string = '得分: ' + this.score.toString();
  },
  // combo重置
  resetCombo: function () {
    this.comboNum = 0;
    this.comboDisplay.string = this.comboNum.toString();
  },
  // 血量重置
  resetBlood: function () {
    this._bloodVolume = this.tili;
    // 更新 bloodDisplay Label 的文字
    this.bloodDisplay.string = '体力: ' + this.tili.toString() + ' / ' + this._bloodVolume.toString();
    this.hpBar.width = ((500 / this.tili) * this._bloodVolume);
  },
  // 跳跃状态重置
  resetJumpEve: function () {
    this._isLeft = true;
    this._isRight = true;
  },
  // 是否复活界面显示
  ifFuHuoShow: function () {
    this.prefabManager.delAllMst();
    this.ifFuHuoDisplay.active = true;
    this.isRuning = false;
    this._isSkill = false;
    this._isBati = false;
    this.whiteBtn.getComponent(cc.Button).enabled = false;
    this.blackBtn.getComponent(cc.Button).enabled = false;
    this.pauseBtn.getComponent(cc.Button).enabled = false;
    this.skillBtn.getComponent(cc.Button).enabled = false;
    this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = false;
    this.skillBar.pause();
    this.player.onPlayerPause();
    cc.audioEngine.pauseAll();
    cc.director.getCollisionManager().enabled = false;
    cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.keyDonwn, this);
  },
  // 复活按钮按下
  fuHuoNow: function () {
    this.player.onPlayerReLive();
    this.ifFuHuoDisplay.active = false;
    this.fuhuoNum = 0;
    // 平a技能cd
    this.pingA = 0;
    this.resetBlood();
    this.isRuning = true;
    this._isSkill = true;
    this._isBati = true;
    this.whiteBtn.getComponent(cc.Button).enabled = true;
    this.blackBtn.getComponent(cc.Button).enabled = true;
    this.pauseBtn.getComponent(cc.Button).enabled = true;
    this.skillBtn.getComponent(cc.Button).enabled = true;
    this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = true;
    this.skillBar.resume();
    this.player.onPlayerResume();
    cc.audioEngine.resumeAll();
    cc.director.getCollisionManager().enabled = true;
    cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.keyDonwn, this);
  },
  // 游戏结束 & 不复活按钮
  gameOver: function () {
    this.ifFuHuoDisplay.active = false;
    this.endPageDisplay.active = true;
    this.prefabManager.mstMoveSpeed = 0;
    this.isRuning = false;
    this._isSkill = false;
    this._isBati = false;
    // 分数显示
    var scoDis = this.endPageDisplay.getChildByName('PanelAll').getChildByName('count');
    scoDis.getChildByName('ScoreNow').getComponent(cc.Label).string = this.score.toString();
    scoDis.getChildByName('ScoreMax').getComponent(cc.Label).string = this.maxScore.toString();
    var bouns = Math.ceil(this.score / 20);
    scoDis.getChildByName('Bonus').getComponent(cc.Label).string = bouns.toString();
    // 获得云端数据 上传云端和子域服务端最高分
    this.totalMoney += bouns;
    if (this.maxScore >= this.score) {
      wx.setUserCloudStorage({
        KVDataList: [{
          key: 'maxScore',
          value: this.maxScore.toString()
        }],
      });
      const db = wx.cloud.database();
      db.collection('ganjiangmoye').doc(this._id).update({
        data: {
          maxScore: this.maxScore,
          totalMoney: this.totalMoney
        }
      })
    } else if (this.maxScore <= this.score) {
      wx.setUserCloudStorage({
        KVDataList: [{
          key: 'maxScore',
          value: this.score.toString()
        }],
      });
      const db = wx.cloud.database();
      db.collection('ganjiangmoye').doc(this._id).update({
        data: {
          maxScore: this.score,
          totalMoney: this.totalMoney
        }
      })
    }


    this.whiteBtn.getComponent(cc.Button).enabled = false;
    this.blackBtn.getComponent(cc.Button).enabled = false;
    this.pauseBtn.getComponent(cc.Button).enabled = false;

    this.skillBar.setCurrentTime(0);
    this.skillBar.stop();
    this.skillBtn.getComponent(cc.Button).enabled = false;
    this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = false;

    this.player.onPlayerStopMove();
    this.prefabManager.delAllMst();
    this.prefabManager.stopAddMst();
    this.skillCD.getComponent(cc.ProgressBar).progress = 0;
    this.batiCD.getComponent(cc.ProgressBar).progress = 0;
    cc.audioEngine.stopAll();
    cc.audioEngine.play(this.gameOverAudio);
    // 关闭碰撞检测
    cc.director.getCollisionManager().enabled = false;
    cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.keyDonwn, this);
    this.uiDisplayOff();
  },
  // 暂停游戏
  pauseDisplay: function () {
    this.panelPause.active = true;
    this.isRuning = false;
    // this.bishajiOn = false;
    this._isSkill = false;
    this._isBati = false;
    this.whiteBtn.getComponent(cc.Button).enabled = false;
    this.blackBtn.getComponent(cc.Button).enabled = false;
    this.pauseBtn.getComponent(cc.Button).enabled = false;
    this.skillBtn.getComponent(cc.Button).enabled = false;
    this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = false;
    this.skillBar.pause();
    this.player.onPlayerPause();
    cc.audioEngine.pauseAll();
    cc.director.getCollisionManager().enabled = false;
    cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.keyDonwn, this);
  },
  // 继续游戏
  resume: function () {
    this.ifFuHuoDisplay.active = false;
    this.panelPause.active = false;
    this.isRuning = true;
    // this.bishajiOn = true;
    this._isSkill = true;
    this._isBati = true;
    this.whiteBtn.getComponent(cc.Button).enabled = true;
    this.blackBtn.getComponent(cc.Button).enabled = true;
    this.pauseBtn.getComponent(cc.Button).enabled = true;
    this.skillBtn.getComponent(cc.Button).enabled = true;
    this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = true;
    this.skillBar.resume();
    this.player.onPlayerResume();
    cc.audioEngine.resumeAll();
    cc.director.getCollisionManager().enabled = true;
    cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.keyDonwn, this);
  },
  // 重新开始
  restart: function () {
    this.fuhuoNum = 1;
    this.endPageDisplay.active = false;
    if (this.speed == 1) {
      this.prefabManager.mstMoveSpeed = 6;
    } else if (this.speed == 2) {
      this.prefabManager.mstMoveSpeed = 12;
    } else if (this.speed == 3) {
      this.prefabManager.mstMoveSpeed = 18;
    }
    this._skillTime = 0;
    this._totalNum = 0;
    this.BarSkill.getChildByName('Bar').getComponent(cc.ProgressBar).progress = this._totalNum / 100;
    this._isSkill = false;
    this._isBati = false;
    this._skillShow = false;
    this.skillBar.stop();
    this.isRuning = false;
    this.panelPause.active = false;
    this.startGameDisplay.x = 0;
    this.whiteBtn.getComponent(cc.Button).enabled = false;
    this.blackBtn.getComponent(cc.Button).enabled = false;
    this.pauseBtn.getComponent(cc.Button).enabled = false;
    this.skillBtn.getComponent(cc.Button).enabled = false;
    this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = true;
    this.skillBar.setCurrentTime(0);
    this.skillBar.stop();
    this.player.onPlayerStopMove();
    this.skillCD.getComponent(cc.ProgressBar).progress = 0;
    this.batiCD.getComponent(cc.ProgressBar).progress = 0;
    this.prefabManager.delAllMst();
    this.prefabManager.stopAddMst();
    cc.audioEngine.stopAll();
    // 关闭碰撞检测
    cc.director.getCollisionManager().enabled = false;
    cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.keyDonwn, this);
    this.uiDisplayOff();
  },
  // 退出游戏
  quitGame: function () {
    this.prefabManager.mstMoveSpeed = 0;
    this.configurationTable.removeConfig();
    this.isRuning = false;
    this.whiteBtn.getComponent(cc.Button).enabled = false;
    this.blackBtn.getComponent(cc.Button).enabled = false;
    this.pauseBtn.getComponent(cc.Button).enabled = false;
    this.skillBtn.getComponent(cc.Button).enabled = false;
    this.batiBar.getChildByName('BatiBtn').getComponent(cc.Button).enabled = false;
    this.player.onPlayerStopMove();
    this.prefabManager.delAllMst();
    this.prefabManager.stopAddMst();
    cc.audioEngine.stopAll();
    // 关闭碰撞检测
    cc.director.getCollisionManager().enabled = false;
    cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.keyDonwn, this);
    cc.director.loadScene("main", function () {
      cc.log("跳转main场景");
    });
  },
  // 页面跳转
  goBackMain: function () {
    cc.director.loadScene("main", function () {
      cc.log("跳转main场景");
    });
  }
});
module.exports = Game;